WithExceptionOnFailure(TException) Method

CuttingEdge.Conditions

Returns a new AlternativeExceptionCondition that allows you to specify the exception type that has to be thrown in case a a validation fails.

Namespace:  CuttingEdge.Conditions
Assembly:  CuttingEdge.Conditions (in CuttingEdge.Conditions.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function WithExceptionOnFailure(Of TException As Exception) As AlternativeExceptionCondition
C#
public static AlternativeExceptionCondition WithExceptionOnFailure<TException>()
where TException : Exception
Visual C++
public:
generic<typename TException>
where TException : Exception
static AlternativeExceptionCondition^ WithExceptionOnFailure()
JavaScript
JavaScript does not support generic types or methods.

Type Parameters

TException
The type of the exception to throw.

Return Value

A new AlternativeExceptionCondition.

Examples

The following example shows how to use the WithExceptionOnFailure method.
 Copy Code
  using CuttingEdge.Conditions;
  
  public class Point
  {
      private readonly int x;
      private readonly int y;
      
      public Point(int x, int y)
      {
          // Throws an InvalidOperationException when x is less than 0
          Condition.WithExceptionOnFailure<InvalidOperationException>().Requires(x, "x")
              .IsGreaterOrEqual(0)
              .IsLessThan(100);
          
          this.x = x;
          this.y = y;
      }
      
      public int X { get { return this.x; } }
      public int Y { get { return this.y; } }
  }
  
See the ConditionValidator<(Of <(T>)>) class for more code examples.

Exceptions

ExceptionCondition
System..::.ArgumentException Thrown when the supplied TException is abstract or does not contain a public constructor with a single parameter of type String.

See Also